/** * Basic structure: TC_Class is the public class that is returned upon being called * * So, if you do * var tc = $(".timer").TimeCircles(); * * tc will contain an instance of the public TimeCircles class. It is important to * note that TimeCircles is not chained in the conventional way, check the * documentation for more info on how TimeCircles can be chained. * * After being called/created, the public TimerCircles class will then- for each element * within it's collection, either fetch or create an instance of the private class. * Each function called upon the public class will be forwarded to each instance * of the private classes within the relevant element collection **/ (function ($) { /** * Converts hex color code into object containing integer values for the r,g,b use * This function (hexToRgb) originates from: * //stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb * @param {string} hex color code */ function hexToRgb(hex) { // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF") var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i; hex = hex.replace(shorthandRegex, function (m, r, g, b) { return r + r + g + g + b + b; }); var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); return result ? { r: parseInt(result[1], 16), g: parseInt(result[2], 16), b: parseInt(result[3], 16) } : null; } /** * Function s4() and guid() originate from: * //stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript */ function s4() { return Math.floor((1 + Math.random()) * 0x10000) .toString(16) .substring(1); } /** * Creates a unique id * @returns {String} */ function guid() { return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4(); } var TC_Instance_List = {}; var TC_Instance = function (element, options) { this.element = element; this.container; this.timer = null; this.data = { text_elements: { Days: null, Hours: null, Minutes: null, Seconds: null }, attributes: { //canvas: null, context: null, item_size: null, line_width: null, radius: null, outer_radius: null }, state: { fading: { Days: false, Hours: false, Minutes: false, Seconds: false } } }; this.listeners = []; this.config = null; this.setOptions(options); this.container = $("